package karabut.hw3;

public class Main {
	private final static String INPUT_EXT = ".pert";
	private final static String OUTPUT_EXT = ".dot";

	public static void main(String[] args) {
		if (args.length != 1) {
			System.out.println("Please specify pert file.");
		}
		String inputFile = args[0];
		
		String outputFile;
		if (inputFile.endsWith(INPUT_EXT)) {
			outputFile = inputFile.substring(0, inputFile.length()-INPUT_EXT.length()) + OUTPUT_EXT; 
		} else {
			outputFile = inputFile + OUTPUT_EXT;
		}
		
		try {
			System.out.println("Loading chart from file " + inputFile + " ...");
			PertLoader loader = new PertLoader();
			PertChart chart = loader.load(inputFile);
			System.out.println("done.");
			
			System.out.println("Saving chart to file " + outputFile + " ...");
			PertSaver saver = new PertSaver();
			saver.save(chart, outputFile);
			System.out.println("done.");
		} catch (Exception e) {
			System.out.println("Error occured during processing PERT file:");
			e.printStackTrace();
		}
	}

}
